package org.nowcoder.leetcode.bit;


/**
 * Title  : 50. Pow(x, n)
 * Source : https://leetcode.cn/problems/powx-n/?envType=study-plan-v2&envId=top-interview-150
 * Author : XrazYang
 * Date   : 2023-05-31
 */

public class LeetCode_50 {
    public double myPow(double x, int n) {
        if (Double.valueOf(x).equals(Double.valueOf(1.0))) {
            return x;
        }

        if (Double.valueOf(x).equals(Double.valueOf(-1.0))) {
            return n % 2 == 0 ? (-(1 / x)) : 1 / x;
        }

        if (n == Integer.MIN_VALUE) {
            x = Math.pow(x, Integer.MAX_VALUE) * x;
            return 1 / x;
        }
        return Math.pow(x, n);
    }
}
